package com.sukaiyi.giteeideaplugin.component;

import javax.swing.*;
import java.awt.*;

public class TranslucenceJPanel extends JPanel {

    private float transparency = 0;

    public TranslucenceJPanel() {

    }

    public TranslucenceJPanel(float transparency) {
        this.transparency = transparency;
    }

    public void setTransparent(float transparency) {
        this.transparency = transparency;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D graphics2d = (Graphics2D) g.create();
        graphics2d.setComposite(AlphaComposite.SrcOver.derive(transparency));
        graphics2d.setColor(getBackground());
        graphics2d.fillRect(0, 0, getWidth(), getHeight());
        graphics2d.dispose();
    }
}
